// This source is subject to the Microsoft Public License.
// See http://www.microsoft.com/resources/sharedsource/licensingbasics/sharedsourcelicenses.mspx.
// All other rights reserved.

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Web.UI.WebControls;
using System.Windows.Forms;
using System.Xml;

using QuoteAdvantageEditor.CrmSdk;


namespace QuoteAdvantageEditor
{
	/// <summary>
	/// Summary description for RuleDlg.
	/// </summary>
	public class RuleDlg : System.Windows.Forms.Form
	{
      private AuthoringEngine eng = null;
      protected XmlNode objInputRuleNode = null;
      protected XmlNode objOutputRuleNode = null;
     
      private System.Windows.Forms.Button btnOK;
      private System.Windows.Forms.Button btnCancel;
      private System.Windows.Forms.Label label5;
      private System.Windows.Forms.RadioButton btnNotCompatibleWith;
      private System.Windows.Forms.GroupBox groupBox1;
      private System.Windows.Forms.RadioButton btnRequiresItem;
      private System.Windows.Forms.RadioButton btnRequiresCategory;
      private System.Windows.Forms.TextBox txtNotCompatibleWithItemId;
      private System.Windows.Forms.TextBox txtRequiresItemId;
      private System.Windows.Forms.TextBox txtRequiresCategoryId;
      private System.Windows.Forms.Label lblNotCompatibleWithItemId;
      private System.Windows.Forms.Label lblRequiresItemId;
      private System.Windows.Forms.Label lblRequiresCategoryId;
      private System.Windows.Forms.TextBox txtComments;
      private System.Windows.Forms.Button btnSearch1;
      private System.Windows.Forms.Button btnSearch2;
      private System.Windows.Forms.TextBox txtLinkedItemId;
      private System.Windows.Forms.RadioButton btnLinkedItem;
      private System.Windows.Forms.Button btnSearch3;
      private System.Windows.Forms.ComboBox ddlLinkedUnitOfMeasure;
      private System.Windows.Forms.Label lblLinkedItemId;
      private System.Windows.Forms.Label lblLinkedUom;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;
      
      public AuthoringEngine Engine
      {
         get { return eng; }
         set { eng = value; }
      }

      public XmlNode InputRuleNode
      {
         get { return objInputRuleNode; }
         set { objInputRuleNode = value; }
      }

      public XmlNode OutputRuleNode
      {
         get { return objOutputRuleNode; }
         set { objOutputRuleNode = value; }
      }

		public RuleDlg()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
         this.btnOK = new System.Windows.Forms.Button();
         this.btnCancel = new System.Windows.Forms.Button();
         this.btnNotCompatibleWith = new System.Windows.Forms.RadioButton();
         this.btnRequiresItem = new System.Windows.Forms.RadioButton();
         this.btnRequiresCategory = new System.Windows.Forms.RadioButton();
         this.lblNotCompatibleWithItemId = new System.Windows.Forms.Label();
         this.txtNotCompatibleWithItemId = new System.Windows.Forms.TextBox();
         this.lblRequiresItemId = new System.Windows.Forms.Label();
         this.lblRequiresCategoryId = new System.Windows.Forms.Label();
         this.txtRequiresItemId = new System.Windows.Forms.TextBox();
         this.txtRequiresCategoryId = new System.Windows.Forms.TextBox();
         this.label5 = new System.Windows.Forms.Label();
         this.txtComments = new System.Windows.Forms.TextBox();
         this.groupBox1 = new System.Windows.Forms.GroupBox();
         this.ddlLinkedUnitOfMeasure = new System.Windows.Forms.ComboBox();
         this.lblLinkedUom = new System.Windows.Forms.Label();
         this.btnSearch3 = new System.Windows.Forms.Button();
         this.lblLinkedItemId = new System.Windows.Forms.Label();
         this.txtLinkedItemId = new System.Windows.Forms.TextBox();
         this.btnLinkedItem = new System.Windows.Forms.RadioButton();
         this.btnSearch2 = new System.Windows.Forms.Button();
         this.btnSearch1 = new System.Windows.Forms.Button();
         this.groupBox1.SuspendLayout();
         this.SuspendLayout();
         // 
         // btnOK
         // 
         this.btnOK.Location = new System.Drawing.Point(252, 256);
         this.btnOK.Name = "btnOK";
         this.btnOK.TabIndex = 18;
         this.btnOK.Text = "OK";
         this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
         // 
         // btnCancel
         // 
         this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
         this.btnCancel.Location = new System.Drawing.Point(332, 256);
         this.btnCancel.Name = "btnCancel";
         this.btnCancel.TabIndex = 19;
         this.btnCancel.Text = "Cancel";
         this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
         // 
         // btnNotCompatibleWith
         // 
         this.btnNotCompatibleWith.Location = new System.Drawing.Point(20, 24);
         this.btnNotCompatibleWith.Name = "btnNotCompatibleWith";
         this.btnNotCompatibleWith.Size = new System.Drawing.Size(128, 16);
         this.btnNotCompatibleWith.TabIndex = 1;
         this.btnNotCompatibleWith.Text = "Not Compatible With";
         this.btnNotCompatibleWith.CheckedChanged += new System.EventHandler(this.btnNotCompatibleWith_CheckedChanged);
         // 
         // btnRequiresItem
         // 
         this.btnRequiresItem.Location = new System.Drawing.Point(20, 60);
         this.btnRequiresItem.Name = "btnRequiresItem";
         this.btnRequiresItem.Size = new System.Drawing.Size(96, 16);
         this.btnRequiresItem.TabIndex = 4;
         this.btnRequiresItem.Text = "Requires Item";
         this.btnRequiresItem.CheckedChanged += new System.EventHandler(this.btnRequiresItem_CheckedChanged);
         // 
         // btnRequiresCategory
         // 
         this.btnRequiresCategory.Location = new System.Drawing.Point(20, 96);
         this.btnRequiresCategory.Name = "btnRequiresCategory";
         this.btnRequiresCategory.Size = new System.Drawing.Size(120, 16);
         this.btnRequiresCategory.TabIndex = 7;
         this.btnRequiresCategory.Text = "Requires Category";
         this.btnRequiresCategory.CheckedChanged += new System.EventHandler(this.btnRequiresCategory_CheckedChanged);
         // 
         // lblNotCompatibleWithItemId
         // 
         this.lblNotCompatibleWithItemId.Location = new System.Drawing.Point(160, 24);
         this.lblNotCompatibleWithItemId.Name = "lblNotCompatibleWithItemId";
         this.lblNotCompatibleWithItemId.Size = new System.Drawing.Size(48, 16);
         this.lblNotCompatibleWithItemId.TabIndex = 2;
         this.lblNotCompatibleWithItemId.Text = "Item ID:";
         this.lblNotCompatibleWithItemId.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
         // 
         // txtNotCompatibleWithItemId
         // 
         this.txtNotCompatibleWithItemId.Location = new System.Drawing.Point(212, 20);
         this.txtNotCompatibleWithItemId.Name = "txtNotCompatibleWithItemId";
         this.txtNotCompatibleWithItemId.Size = new System.Drawing.Size(148, 21);
         this.txtNotCompatibleWithItemId.TabIndex = 3;
         this.txtNotCompatibleWithItemId.Text = "";
         // 
         // lblRequiresItemId
         // 
         this.lblRequiresItemId.Location = new System.Drawing.Point(160, 60);
         this.lblRequiresItemId.Name = "lblRequiresItemId";
         this.lblRequiresItemId.Size = new System.Drawing.Size(48, 16);
         this.lblRequiresItemId.TabIndex = 5;
         this.lblRequiresItemId.Text = "Item ID:";
         this.lblRequiresItemId.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
         // 
         // lblRequiresCategoryId
         // 
         this.lblRequiresCategoryId.Location = new System.Drawing.Point(136, 96);
         this.lblRequiresCategoryId.Name = "lblRequiresCategoryId";
         this.lblRequiresCategoryId.Size = new System.Drawing.Size(72, 16);
         this.lblRequiresCategoryId.TabIndex = 8;
         this.lblRequiresCategoryId.Text = "Category ID:";
         this.lblRequiresCategoryId.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
         // 
         // txtRequiresItemId
         // 
         this.txtRequiresItemId.Location = new System.Drawing.Point(212, 56);
         this.txtRequiresItemId.Name = "txtRequiresItemId";
         this.txtRequiresItemId.Size = new System.Drawing.Size(148, 21);
         this.txtRequiresItemId.TabIndex = 6;
         this.txtRequiresItemId.Text = "";
         // 
         // txtRequiresCategoryId
         // 
         this.txtRequiresCategoryId.Location = new System.Drawing.Point(212, 92);
         this.txtRequiresCategoryId.Name = "txtRequiresCategoryId";
         this.txtRequiresCategoryId.Size = new System.Drawing.Size(148, 21);
         this.txtRequiresCategoryId.TabIndex = 9;
         this.txtRequiresCategoryId.Text = "";
         // 
         // label5
         // 
         this.label5.Location = new System.Drawing.Point(12, 224);
         this.label5.Name = "label5";
         this.label5.Size = new System.Drawing.Size(64, 16);
         this.label5.TabIndex = 16;
         this.label5.Text = "Comments:";
         this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
         // 
         // txtComments
         // 
         this.txtComments.Location = new System.Drawing.Point(80, 220);
         this.txtComments.Name = "txtComments";
         this.txtComments.Size = new System.Drawing.Size(324, 21);
         this.txtComments.TabIndex = 17;
         this.txtComments.Text = "";
         // 
         // groupBox1
         // 
         this.groupBox1.Controls.Add(this.ddlLinkedUnitOfMeasure);
         this.groupBox1.Controls.Add(this.lblLinkedUom);
         this.groupBox1.Controls.Add(this.btnSearch3);
         this.groupBox1.Controls.Add(this.lblLinkedItemId);
         this.groupBox1.Controls.Add(this.txtLinkedItemId);
         this.groupBox1.Controls.Add(this.btnLinkedItem);
         this.groupBox1.Controls.Add(this.btnSearch2);
         this.groupBox1.Controls.Add(this.btnSearch1);
         this.groupBox1.Controls.Add(this.btnNotCompatibleWith);
         this.groupBox1.Controls.Add(this.btnRequiresItem);
         this.groupBox1.Controls.Add(this.btnRequiresCategory);
         this.groupBox1.Controls.Add(this.lblNotCompatibleWithItemId);
         this.groupBox1.Controls.Add(this.lblRequiresItemId);
         this.groupBox1.Controls.Add(this.txtNotCompatibleWithItemId);
         this.groupBox1.Controls.Add(this.txtRequiresItemId);
         this.groupBox1.Controls.Add(this.lblRequiresCategoryId);
         this.groupBox1.Controls.Add(this.txtRequiresCategoryId);
         this.groupBox1.Location = new System.Drawing.Point(8, 12);
         this.groupBox1.Name = "groupBox1";
         this.groupBox1.Size = new System.Drawing.Size(400, 192);
         this.groupBox1.TabIndex = 0;
         this.groupBox1.TabStop = false;
         this.groupBox1.Text = "Rule Type";
         // 
         // ddlLinkedUnitOfMeasure
         // 
         this.ddlLinkedUnitOfMeasure.DisplayMember = "Text";
         this.ddlLinkedUnitOfMeasure.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
         this.ddlLinkedUnitOfMeasure.Location = new System.Drawing.Point(232, 156);
         this.ddlLinkedUnitOfMeasure.Name = "ddlLinkedUnitOfMeasure";
         this.ddlLinkedUnitOfMeasure.Size = new System.Drawing.Size(156, 21);
         this.ddlLinkedUnitOfMeasure.TabIndex = 15;
         this.ddlLinkedUnitOfMeasure.ValueMember = "Value";
         // 
         // lblLinkedUom
         // 
         this.lblLinkedUom.Location = new System.Drawing.Point(140, 160);
         this.lblLinkedUom.Name = "lblLinkedUom";
         this.lblLinkedUom.Size = new System.Drawing.Size(92, 16);
         this.lblLinkedUom.TabIndex = 14;
         this.lblLinkedUom.Text = "Unit of Measure:";
         this.lblLinkedUom.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
         // 
         // btnSearch3
         // 
         this.btnSearch3.Location = new System.Drawing.Point(364, 128);
         this.btnSearch3.Name = "btnSearch3";
         this.btnSearch3.Size = new System.Drawing.Size(24, 24);
         this.btnSearch3.TabIndex = 13;
         this.btnSearch3.Text = "...";
         this.btnSearch3.Click += new System.EventHandler(this.btnSearch3_Click);
         // 
         // lblLinkedItemId
         // 
         this.lblLinkedItemId.Location = new System.Drawing.Point(136, 132);
         this.lblLinkedItemId.Name = "lblLinkedItemId";
         this.lblLinkedItemId.Size = new System.Drawing.Size(72, 16);
         this.lblLinkedItemId.TabIndex = 11;
         this.lblLinkedItemId.Text = "Item ID:";
         this.lblLinkedItemId.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
         // 
         // txtLinkedItemId
         // 
         this.txtLinkedItemId.Location = new System.Drawing.Point(212, 128);
         this.txtLinkedItemId.Name = "txtLinkedItemId";
         this.txtLinkedItemId.Size = new System.Drawing.Size(148, 21);
         this.txtLinkedItemId.TabIndex = 12;
         this.txtLinkedItemId.Text = "";
         this.txtLinkedItemId.TextChanged += new System.EventHandler(this.txtLinkedItemId_TextChanged);
         // 
         // btnLinkedItem
         // 
         this.btnLinkedItem.Location = new System.Drawing.Point(20, 132);
         this.btnLinkedItem.Name = "btnLinkedItem";
         this.btnLinkedItem.Size = new System.Drawing.Size(92, 16);
         this.btnLinkedItem.TabIndex = 10;
         this.btnLinkedItem.Text = "Linked Item";
         this.btnLinkedItem.CheckedChanged += new System.EventHandler(this.btnLinkedItem_CheckedChanged);
         // 
         // btnSearch2
         // 
         this.btnSearch2.Location = new System.Drawing.Point(364, 56);
         this.btnSearch2.Name = "btnSearch2";
         this.btnSearch2.Size = new System.Drawing.Size(24, 24);
         this.btnSearch2.TabIndex = 11;
         this.btnSearch2.Text = "...";
         this.btnSearch2.Click += new System.EventHandler(this.btnSearch2_Click);
         // 
         // btnSearch1
         // 
         this.btnSearch1.Location = new System.Drawing.Point(364, 20);
         this.btnSearch1.Name = "btnSearch1";
         this.btnSearch1.Size = new System.Drawing.Size(24, 24);
         this.btnSearch1.TabIndex = 10;
         this.btnSearch1.Text = "...";
         this.btnSearch1.Click += new System.EventHandler(this.btnSearch1_Click);
         // 
         // RuleDlg
         // 
         this.AcceptButton = this.btnOK;
         this.AutoScaleBaseSize = new System.Drawing.Size(5, 14);
         this.CancelButton = this.btnCancel;
         this.ClientSize = new System.Drawing.Size(418, 292);
         this.Controls.Add(this.groupBox1);
         this.Controls.Add(this.txtComments);
         this.Controls.Add(this.label5);
         this.Controls.Add(this.btnCancel);
         this.Controls.Add(this.btnOK);
         this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
         this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
         this.MaximizeBox = false;
         this.MinimizeBox = false;
         this.Name = "RuleDlg";
         this.ShowInTaskbar = false;
         this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
         this.Text = "Rule";
         this.Load += new System.EventHandler(this.RuleDlg_Load);
         this.groupBox1.ResumeLayout(false);
         this.ResumeLayout(false);

      }
		#endregion
      
      private void RuleDlg_Load(object sender, System.EventArgs e)
      {
         SetControlValues();
         RefreshView();
      }

      private void btnOK_Click(object sender, System.EventArgs e)
      {
         GetControlValues();
         this.DialogResult = DialogResult.OK;
         this.Close();
      }

      private void btnCancel_Click(object sender, System.EventArgs e)
      {
         this.Close();
      }           

      private void btnNotCompatibleWith_CheckedChanged(object sender, System.EventArgs e)
      {
         RefreshView();
      }

      private void btnRequiresItem_CheckedChanged(object sender, System.EventArgs e)
      {
         RefreshView();
      }

      private void btnRequiresCategory_CheckedChanged(object sender, System.EventArgs e)
      {
         RefreshView();
      }

      private void RefreshView()
      {
         txtNotCompatibleWithItemId.Visible = false;
         btnSearch1.Visible = false;
         txtRequiresItemId.Visible = false;
         txtRequiresCategoryId.Visible = false;
         lblNotCompatibleWithItemId.Visible = false;
         lblRequiresItemId.Visible = false;
         lblRequiresCategoryId.Visible = false;
         btnSearch2.Visible = false;
         lblLinkedItemId.Visible = false;
         txtLinkedItemId.Visible = false;
         btnSearch3.Visible = false;
         lblLinkedUom.Visible = false;
         ddlLinkedUnitOfMeasure.Visible = false;
      
         if (btnNotCompatibleWith.Checked)
         {
            txtNotCompatibleWithItemId.Visible = true;
            btnSearch1.Visible = true;
            lblNotCompatibleWithItemId.Visible = true;
         }
         else if (btnRequiresItem.Checked)
         {
            txtRequiresItemId.Visible = true;
            lblRequiresItemId.Visible = true;
            btnSearch2.Visible = true;
         }
         else if (btnRequiresCategory.Checked)
         {
            txtRequiresCategoryId.Visible = true;
            lblRequiresCategoryId.Visible = true;
         }   
         else if (btnLinkedItem.Checked)
         {
            lblLinkedItemId.Visible = true;
            txtLinkedItemId.Visible = true;
            btnSearch3.Visible = true;
            lblLinkedUom.Visible = true;
            ddlLinkedUnitOfMeasure.Visible = true;
         }

      }

      private void SetControlValues()
      {
         switch (objInputRuleNode.Name)
         {
            case "RequiresCategory":
               btnRequiresCategory.Checked = true;
               txtRequiresCategoryId.Text = objInputRuleNode.InnerText;
               break;

            case "RequiresItem":
               btnRequiresItem.Checked = true;
               txtRequiresItemId.Text = objInputRuleNode.InnerText; 
               break;

            case "NotCompatibleWith":
               btnNotCompatibleWith.Checked = true;
               txtNotCompatibleWithItemId.Text = objInputRuleNode.InnerText;
               break;
            
            case "LinkedItem":
               btnLinkedItem.Checked = true;
               txtLinkedItemId.Text = objInputRuleNode.InnerText;   
               RefreshLinkItemUom();
               break;
         }

         if (objInputRuleNode.NextSibling != null)
         {
            if (objInputRuleNode.NextSibling.NodeType == XmlNodeType.Comment)
               txtComments.Text = objInputRuleNode.NextSibling.InnerText;
         }
      }

      private void GetControlValues()
      {
         if (btnNotCompatibleWith.Checked)
         {
            objOutputRuleNode = objInputRuleNode.OwnerDocument.CreateElement("", "NotCompatibleWith", "");
            objOutputRuleNode.InnerText = txtNotCompatibleWithItemId.Text;
         }
         else if (btnRequiresItem.Checked)
         {
            objOutputRuleNode = objInputRuleNode.OwnerDocument.CreateElement("", "RequiresItem", "");
            objOutputRuleNode.InnerText = txtRequiresItemId.Text;
         }
         else if (btnRequiresCategory.Checked)
         {
            objOutputRuleNode = objInputRuleNode.OwnerDocument.CreateElement("", "RequiresCategory", "");
            objOutputRuleNode.InnerText = txtRequiresCategoryId.Text;
         }    
         else if (btnLinkedItem.Checked)
         {
            objOutputRuleNode = objInputRuleNode.OwnerDocument.CreateElement("", "LinkedItem", "");
            objOutputRuleNode.InnerText = txtLinkedItemId.Text;
            XmlAttribute objAttrib = objInputRuleNode.OwnerDocument.CreateAttribute("", "uom", "");

            objAttrib.Value = ""; 
            objOutputRuleNode.Attributes.Append(objAttrib);

            string strUomValue = "";

            if (ddlLinkedUnitOfMeasure.SelectedIndex != -1)
            {
               ListItem objItem = (ListItem)ddlLinkedUnitOfMeasure.SelectedItem;
               strUomValue = objItem.Value;
            }

            objOutputRuleNode.Attributes["uom"].Value = strUomValue; 
         }
    
         // Store comment
         XmlComment objCommentsNode = null;

         if (objInputRuleNode.NextSibling != null)
         {
            if (objInputRuleNode.NextSibling.NodeType == XmlNodeType.Comment)
               objCommentsNode = (XmlComment)objInputRuleNode.NextSibling;
         }

         if (objCommentsNode == null)
         {
            objCommentsNode = objInputRuleNode.OwnerDocument.CreateComment("");
            objInputRuleNode.ParentNode.InsertAfter(objCommentsNode, objInputRuleNode);
         }

         objCommentsNode.Value = txtComments.Text; 
      }

      private void RefreshLinkItemUom()
      {
         string strDefaultUom = "";
         
         if (objInputRuleNode.Attributes["uom"] != null)
         {
            strDefaultUom = objInputRuleNode.Attributes["uom"].Value;               
         }
         
         Product objProduct = eng.LoadProductFromProductNumber(txtLinkedItemId.Text);

         ddlLinkedUnitOfMeasure.Items.Clear();
         
         if (objProduct != null)
         {              
            ArrayList objUomList = eng.LoadUnitOfMeasureList(objProduct);

            ddlLinkedUnitOfMeasure.Items.Clear();
            ddlLinkedUnitOfMeasure.Items.Add(new ListItem("[Default]", ""));  
            ddlLinkedUnitOfMeasure.SelectedIndex = 0;

            foreach(uom objUnit in objUomList)
            {
               string strUom = objUnit.uomid.Value.ToString();
               ddlLinkedUnitOfMeasure.Items.Add(new ListItem(objUnit.name, strUom));  
                
               if (strUom == strDefaultUom)
               {
                  ddlLinkedUnitOfMeasure.SelectedIndex = ddlLinkedUnitOfMeasure.Items.Count - 1;
               }
            }
         }      
      }


      private void btnSearch1_Click(object sender, System.EventArgs e)
      {
         LoadCrmProductDlg dlg = new LoadCrmProductDlg();

         dlg.Engine = this.Engine;

         if (DialogResult.OK == dlg.ShowDialog(this))
         {
            txtNotCompatibleWithItemId.Text = dlg.SelectedProduct.ProductNumber;
         }
      }

      private void btnSearch2_Click(object sender, System.EventArgs e)
      {
         LoadCrmProductDlg dlg = new LoadCrmProductDlg();

         dlg.Engine = this.Engine;

         if (DialogResult.OK == dlg.ShowDialog(this))
         {
            txtRequiresItemId.Text = dlg.SelectedProduct.ProductNumber;
         }
      }

      private void btnLinkedItem_CheckedChanged(object sender, System.EventArgs e)
      {
         RefreshView();
      }

      private void btnSearch3_Click(object sender, System.EventArgs e)
      {
         LoadCrmProductDlg dlg = new LoadCrmProductDlg();

         dlg.Engine = this.Engine;

         if (DialogResult.OK == dlg.ShowDialog(this))
         {
            txtLinkedItemId.Text = dlg.SelectedProduct.ProductNumber;
            RefreshLinkItemUom();
         }
      }

      private void txtLinkedItemId_TextChanged(object sender, System.EventArgs e)
      {
         RefreshLinkItemUom();
      }



	} // end class
}
